<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
	
if( !function_exists( 'form_countries' ) )
{
	function form_countries( $name, $selected = null )
	{
		$CI =& get_instance();
		
		$CI->config->load( 'countries' );
		
		$country_list = $CI->config->item( 'country_list' );
		
		$form = '<select name="'.$name.'" class="selectpicker" data-live-search="true"';
		
		$form .= ">";
		
		foreach( $country_list as $key => $value )
		{
			$form .= "\n".'<option value="'.$key.'"';
			
			if( $key == $selected )
			{
				$form .= ' selected>';
			}
			else
			{
				$form .= '>';
			}
			
			$form .= ucwords(strtolower($value)).'</option>';
		}
		
		$form .= "\n</select>";
		
		return $form;
	}
	function get_country( $name )
	{
		$CI =& get_instance();
		
		$CI->config->load( 'countries' );
		
		$country_list = $CI->config->item( 'country_list' );
		$form = '';
		foreach( $country_list as $key => $value )
		{
			if($key==$name)
			{
				$form .= '<img style="width:18px;height:12px;margin-top:-4px" src="'.base_url().'assets/img/flags/'.strtolower($key).'.png" alt="'.ucwords(strtolower($value)).'"/> '. ucwords( strtolower( $value ) );
			}
		}
		
		return $form;
	}
	function abbr_to_country( $name )
	{
		$CI =& get_instance();
		
		$CI->config->load( 'countries' );
		
		$country_list = $CI->config->item( 'country_list' );
		$form = '';
		foreach( $country_list as $key => $value )
		{
			if($key==$name)
			{
				$form .= ucwords( strtolower( $value ) );
			}
		}
		
		return $form;
	}
}